package cn.webrx;

import java.util.Random;
import java.util.Scanner;
/**
 * <p>Description:  try catch finally throw throws
 * <p>Class: Ex5
 * <p>Powered by webrx On 2022-06-14 14:21
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since   17
 */
public class Ex5 {

    public static void main(String[] args) {
        Random rand = new Random();
        Scanner sc = new Scanner(System.in);
        int t = rand.nextInt(1, 101);
        while (true) {
            System.out.print("请输入[1-100] : ");
            int n = 0;
            try {
                n = sc.nextInt();
                if(n<1 || n>100){
                    //throw new GuessNumException("必须输入1-100整数");
                    System.out.println("必须输入1-100整数");
                    continue;
                }
            //} catch (GuessNumException e) {
            //    System.out.println(e.getMessage());
            } catch (Exception e) {
                if("quit".equalsIgnoreCase(sc.next())){
                    System.out.println("游戏结束");
                    break;
                }else{
                    System.out.println("必须输入整数");
                    continue;
                }
            }

            if (n > t) {
                System.out.println("太大了");
            } else if (n < t) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜，你猜对了.");
                break;
            }
        }
    }

    public static void one(String[] args) {
        Random rand = new Random();
        Scanner sc = new Scanner(System.in);
        int t = rand.nextInt(1, 101);
        while (true) {
            System.out.print("请输入[1-100] : ");
            int n = 0;
            if (sc.hasNextInt()) {
                n = sc.nextInt();
            } else {
                System.out.println("请输入整数");
                sc.next();
                continue;
            }
            if (n > t) {
                System.out.println("太大了");
            } else if (n < t) {
                System.out.println("太小了");
            } else {
                System.out.println("恭喜，你猜对了.");
                break;
            }
        }

    }
}
